/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ronsicecream.pos.wh.transaction.returtosupplierdetail;

import com.buanalintas.bynga.Action;
import com.buanalintas.bynga.Field;
import com.buanalintas.bynga.Logger;
import com.buanalintas.bynga.Page;
import com.buanalintas.bynga.Persistence;
import com.ronsicecream.pos.entities.PosTransactionHoReceiptFromSupplierDetail;
import com.ronsicecream.pos.entities.PosTransactionHoReturToSupplierDetail;
import java.util.List;
import javax.persistence.EntityManager;

/**
 *
 * @author user
 */
public class ReturToSupplierDetail extends Page {

    private Field returDetailId;
    private Field returDetailQuantity;
    private Field returDetailPrice;
    private Field returDetailDescription;
    private Field returDetailReturId;
//    private Field returDetailSatuanId;
    private Field returDetailItemId;

    public ReturToSupplierDetail() {
        super();

        setTheClass(PosTransactionHoReturToSupplierDetail.class);




        returDetailId = new Field();
        returDetailId.setName("returDetailId");
        returDetailId.setCaption("id");
        //returDetailId.setInfo("retur detail id");
        returDetailId.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        returDetailId.setInputProperties(" size=\"20\"");
        getFields().add(returDetailId);

        returDetailQuantity = new Field();
        returDetailQuantity.setName("returDetailQuantity");
        returDetailQuantity.setCaption("quantity");
        returDetailQuantity.setRequired(true);
        returDetailQuantity.setListProperties(" align=\"left\" width=\"10%\" nowrap");
        returDetailQuantity.setInputProperties(" size=\"20\"");
        getFields().add(returDetailQuantity);

        returDetailPrice = new Field();
        returDetailPrice.setName("returDetailPrice");
        returDetailPrice.setCaption(" price");
        //returDetailPrice.setInfo("retur detail price");
        returDetailPrice.setListProperties(" align=\"left\" width=\"15%\" nowrap");
        returDetailPrice.setInputProperties(" size=\"20\"");
        getFields().add(returDetailPrice);

        returDetailDescription = new Field();
        returDetailDescription.setName("returDetailDescription");
        returDetailDescription.setCaption("description");
        //returDetailDescription.setInfo("retur detail description");
        returDetailDescription.setListProperties(" align=\"left\" width=\"50%\" nowrap");
        returDetailDescription.setInputProperties(" cols=\"50\" rows=\"5\"");
        returDetailDescription.setInputType(Field.INPUT_TEXT_AREA);
        returDetailDescription.setInputCase(Field.CASE_UPPER);
        getFields().add(returDetailDescription);

        returDetailReturId = new Field();
        returDetailReturId.setName("returDetailReturId");
        returDetailReturId.setCaption("retur");
        //posTransactionReturToSupplier.setInfo("pos transaction retur to supplier");
        returDetailReturId.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        returDetailReturId.setInputProperties(" size=\"20\"");
        getFields().add(returDetailReturId);

//        returDetailSatuanId = new Field();
//        returDetailSatuanId.setName("returDetailSatuanId");
//        returDetailSatuanId.setCaption("satuan");
//        //posMasterSatuan.setInfo("pos master satuan");
//        returDetailSatuanId.setListProperties(" align=\"left\" width=\"10%\" nowrap");
//        returDetailSatuanId.setInputProperties(" size=\"20\"");
//        getFields().add(returDetailSatuanId);

        returDetailItemId = new Field();
        returDetailItemId.setName("returDetailItemId");
        returDetailItemId.setCaption("item");
        //posMasterItem.setInfo("pos master item");
        returDetailItemId.setListProperties(" align=\"left\" width=\"20%\" nowrap");
        returDetailItemId.setInputProperties(" size=\"20\"");
        returDetailItemId.getSelectorColumns().add(new String[]{"itemName", " Nama", "width=\"40%\""});
        returDetailItemId.getSelectorColumns().add(new String[]{"itemCode", " Code", "width=\"10%\" nowrap"});
        returDetailItemId.getSelectorColumns().add(new String[]{"itemTypeId", " Type", "width=\"20%\""});
        returDetailItemId.getSelectorColumns().add(new String[]{"itemMinimum", " Minimum", "width=\"10%\""});
        returDetailItemId.getSelectorColumns().add(new String[]{"itemSatuanId", " Satuan", "width=\"10%\""});
        returDetailItemId.getSelectorColumns().add(new String[]{"itemRasaId", " Rasa", "width=\"10%\""});
        getFields().add(returDetailItemId);


        getActions().add(Action.TRANS_DETAIL_LIST);
        getActions().add(Action.TRANS_DETAIL_ADD);
        getActions().add(Action.TRANS_DETAIL_EDIT);

        fillFields();

        getFieldsAdd().clear();
        getFieldsAdd().add(returDetailItemId);
        getFieldsAdd().add(returDetailQuantity);
        getFieldsAdd().add(returDetailDescription);

        getFieldsEdit().clear();
        getFieldsEdit().add(returDetailItemId);
        getFieldsEdit().add(returDetailQuantity);
        getFieldsEdit().add(returDetailDescription);

        getFieldsList().clear();
        getFieldsList().add(returDetailItemId);
        getFieldsList().add(returDetailQuantity);
        getFieldsList().add(returDetailDescription);
    }

    @Override
    public void loadDetail(List datas, String id) {
        try {
            EntityManager em = getEntityManager();
            List<PosTransactionHoReceiptFromSupplierDetail> request = em.createQuery("SELECT t FROM PosTransactionHoReceiptFromSupplierDetail t WHERE t.receiptDetailReceiptId.receiptId='" + id.toString() + "'").setHint(Persistence.REFRESH_HINT, true).getResultList();
            datas.clear();
            for (PosTransactionHoReceiptFromSupplierDetail receiptDetail : request) {
                PosTransactionHoReturToSupplierDetail rd = new PosTransactionHoReturToSupplierDetail();
                rd.setReturDetailItemId(receiptDetail.getReceiptDetailItemId());
                rd.setReturDetailQuantity(receiptDetail.getReceiptDetailQuantity());
                rd.setReturDetailPrice(receiptDetail.getReceiptDetailPrice());
                rd.setReturDetailDescription(receiptDetail.getReceiptDetailDescription());
                datas.add(rd);
            }
        } catch (Exception e) {
            Logger.getInstance().log(e);
            System.out.println("Errorr :" + e);
        }
    }
}
